/****************************************************************************************************************************
 2    Class Name              : ConsoleHomeController_ACTest
 3    Created By              : Sreekanth SV Vegi
 4    Created on              : 02/26/2013
 5    Description             : Test Class for home page Controller ConsoleHomeController_AC in the West Case Management App.
 6    Version                 : 1.0
 7    ***********************************************************************************************************************/

@isTest
private class ConsoleHomeController_ACTest {
    
    
    
static    West_Case_Names__c   CreateTestWestCase()
{
    
    
   
        String queueName='CM - Queue 11';
    
   try
   
   {
      Set<Id> setAssignedQueueIDs = new Set<Id>();
      for(Group objGroup: [SELECT Id, Name, Type FROM Group WHERE id in (SELECT GroupId FROM GroupMember WHERE userorgroupid = :userInfo.getUserId()) AND Type = 'Queue'])
      {
              setAssignedQueueIDs.add(objGroup.Id);
              
      }
       System.Debug('---STEP1--'+  queueName);
          List<QueueSobject> lstQueueSobject=new List<QueueSobject>();
          lstQueueSobject = [Select Id, QueueId,Queue.Name, SobjectType 
                            from QueueSobject 
                            where Queue.Name Like '%CM - %' 
                            and sobjectType = 'Case'
                            and queueId IN :setAssignedQueueIDs ];
      
       
        queueName= lstQueueSobject[0].Queue.Name;
        System.Debug('---Quename--'+  queueName);
            
      
      
       
       }
       
       Catch(Exception Ex)
       {
           System.Debug('---exp--' +  Ex.getmessage());
       
       }
    try{
    	West_Security_Extensions__c objWestSecurityExtenstion = new West_Security_Extensions__c(Default_West_Support_Case_Status__c='New');
    	insert objWestSecurityExtenstion;	
    }Catch(Exception Ex){
           System.Debug('---exp--' +  Ex.getmessage());
       
    }
    
    
    West_Case_Names__c newwestcasename= new West_Case_Names__c(Name='Academic Probation11', West_Case_Name_Category__c='Academic', West_Case_Name_Activity__c='Program', 
                                                                 West_Case_Group__c='Administration', West_Queue_Name__c=queueName, West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
        insert newwestcasename;
        System.Debug('---queuename--' + queueName);
     return   newwestcasename;

}  
    
    static testMethod void getCaseClickedNextCallTimePriorityTest() {
        
        // Fetch the record type id for West Support
        String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
        //Create west case name record and insert it
        West_Case_Names__c newRecord = CreateTestWestCase();
       
        
        //Create Cases with null next call time of low priority and next call time with highpriority  and insert it
        Case caseWithNextCallTime = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId = westSupportRecordTypeId, next_call__c =(System.now()-100), Status = 'New', Case_Name__c = newRecord.Name,
                                    Priority = '1',Description = 'Test test test', Origin='Phone',Subject='Test');
        Case caseWithNullNextCallTime = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId = westSupportRecordTypeId, next_call__c =null, Status = 'New', Case_Name__c = newRecord.Name,
                                    Priority = '2',Description = 'Test test test2', Origin='Phone',Subject='Test2');
        insert caseWithNextCallTime;
        insert caseWithNullNextCallTime ;

        // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       //System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assert(insertedCaseWithNextCallTime.next_call__c <= System.now());
       
      
        //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
    
    
    
    static testMethod void getCaseClickedNullNextCallTimeTest()
    {
    String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
        
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
         //Create west case name record and insert it
        West_Case_Names__c newRecord = CreateTestWestCase();
        
        //Create Case with next call time and insert it
        Case caseWithNextCallTime = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId = westSupportRecordTypeId, next_call__c = null, Status = 'New', Case_Name__c = newRecord.Name,
                                  Priority = '0',Description = 'Test test test', Origin='Phone',Subject='Test');
        
        //insert the case
        insert caseWithNextCallTime;

        //caseWithNextCallTime.Priority = '0';
        //update caseWithNextCallTime;
        
       // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       //System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assertequals(insertedCaseWithNextCallTime.next_call__c ,null);
       
       ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
       instanceConsoleHomeController_AC.getCaseClicked();
        
    }
    
    
    
    static testMethod void getCaseClickedNullNextCallTimePriorityForTest() {
        
        
        // Fetch the record type id for West Support
        String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
        //Create west case name record and insert it
        West_Case_Names__c newRecord =CreateTestWestCase();
        //Create Cases with null next call time of high priority and next call time with less priority  and insert it
        Case caseWithNextCallTime = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId = westSupportRecordTypeId, next_call__c =(System.now()-100), Status = 'New', Case_Name__c = newRecord.Name,
                                    Priority = '2',Description = 'Test test test', Origin='Phone',Subject='Test');
        Case caseWithNullNextCallTime = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId = westSupportRecordTypeId, next_call__c =null, Status = 'New', Case_Name__c = newRecord.Name,
                                    Priority = '1',Description = 'Test test test2', Origin='Phone',Subject='Test2');
        
       
        insert caseWithNextCallTime;
        insert caseWithNullNextCallTime ;

        // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       //System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assert(insertedCaseWithNextCallTime.next_call__c <= System.now());
       
             
        //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
    
    
    
    static testMethod void getCaseClickedTest() {
        
        //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
      
    }
    
    
      static testMethod void getCaseClickedNullNextCallTimeForTest() {
        // Fetch the record type id for West Support
        String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
         //Create west case name record and insert it
        West_Case_Names__c newRecord = CreateTestWestCase();
        //Create Case with next call time and insert it
        Case caseWithNextCallTime = new Case(AccountId=accountAssociatedWithCase.id,RecordTypeId = westSupportRecordTypeId, next_call__c = (System.now()-100), Status = 'New', Case_Name__c = newRecord.Name,
                                  Priority = '2',Description = 'Test test test', Origin='Phone',Subject='Test');
        
     
        
        insert caseWithNextCallTime;
        
        // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       //System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assert(insertedCaseWithNextCallTime.next_call__c <= System.now());
       
       //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
    
    
    
    
    
    
    /****************UNUSED CODE*******************/
    
    
    /*Created on 28feb morning
    static testMethod void getCaseClickedNextCallTimeNullTest(){
    
        
         Account testaccount=new Account(Name='Test Account');
                insert testaccount;
                 
                 String westProspectiveStudentRecordTypeId = Schema.Sobjecttype.Lead.getRecordTypeInfosByName().get('West - Prospective Student').getRecordTypeId();
                Lead testlead=new Lead(FirstName='Test First Name',LastName='Test Lead',RecordTypeId = westProspectiveStudentRecordTypeId ,Status='New',LeadSource='ALUM',Country='India',Email='abc@df.com',Phone='9957890878',Home_Phone__c='9090909090');
                insert testlead;
                
               
                West_Case_Names__c newRecord = new West_Case_Names__c(Name='Academic Probation', West_Case_Name_Category__c='Academic', West_Case_Name_Activity__c='Program', 
                                                                    West_Case_Group__c='Administration', West_Queue_Name__c='West Case Management - Queue 19', West_Case_Priority__c='1', West_Case_Type_Deadline__c=8);
                insert newRecord;
       
                String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                Case studentCase=new Case(Account=testaccount,Lead__c=testlead.id,Case_Name__c=newRecord.Name,RecordTypeId = westSupportRecordTypeId ,Status='New',Origin='Web',Subject='This is test case by Student',Description='This is test desctiption by Student',Notes__c='Test Notes',Priority='1');
                insert studentCase;
        
        /*Account testaccount=new Account(Name='Test');
        String caseRecordType = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
        /*Creating Case record*/
        /*
        West_Case_Names__c testCaseNames = TestDatabaseCMS.createWestCaseNames();
        Case newRecord = new Case(Account=testaccount,RecordTypeId=caseRecordType, Case_Name__c = testCaseNames.name, Status = 'New', Origin='Phone', Subject='test',Description = '3 Fs Test Description' );
        insert newRecord; */
        //newRecord = [SELECT Queue_Name__c, CaseNumber, Priority, Group__c, Category__c, Activity__c FROM Case
        //                          WHERE Id = :newRecord.Id];
        //return newRecord;
        //Case testcase=TestDatabaseCMS.createCaseForTesting(); 
        //testcase.Account.id=testaccount.id;
        //testcase.Next_Call__c=System.now()+10;
        //update newRecord;
        /*
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();   
        
      }  
        ended */
 }       
        
        
        
        
        
        
        // Fetch the record type id for West Support
       /* 
       String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
        
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        //Create Case with next call time and insert it
        Case caseWithNextCallTime = new Case(Account=accountAssociatedWithCase,RecordTypeId = westSupportRecordTypeId, next_call__c = null, Status = 'New', Case_Name__c = 'No return LOA',
                                  Priority = '0',Description = 'Test test test', Origin='Phone',Subject='Test');
        
        //insert the case
        insert caseWithNextCallTime;

        caseWithNextCallTime.Priority = '0';
        update caseWithNextCallTime;
        
       // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assertequals(insertedCaseWithNextCallTime.next_call__c ,null);
       */
        //Create an instance of the Console Home Controller
       /*  Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE 
                                                        (
                                                          recordtypeid= :Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId() and
                                                          ownerid =:userInfo.getUserId() and
                                                          Status =:'Closed' and
                                                          next_call__c=null)]; 
       
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        */
        //instanceConsoleHomeController_AC.getCaseClicked();
        
    //}
   
 /*
    static testMethod void getCaseClickedNextCallTimePriorityTest() {
        // Fetch the record type id for West Support
        String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
        
        //Create Cases with null next call time of low priority and next call time with highpriority  and insert it
        Case caseWithNextCallTime = new Case(Account=accountAssociatedWithCase,RecordTypeId = westSupportRecordTypeId, next_call__c =(System.now()-100), Status = 'New', Case_Name__c = 'No return LOA',
                                    Priority = '1',Description = 'Test test test', Origin='Phone',Subject='Test');
        Case caseWithNullNextCallTime = new Case(Account=accountAssociatedWithCase,RecordTypeId = westSupportRecordTypeId, next_call__c =null, Status = 'New', Case_Name__c = 'No return LOA',
                                    Priority = '2',Description = 'Test test test2', Origin='Phone',Subject='Test2');
        insert caseWithNextCallTime;
        insert caseWithNullNextCallTime ;

        // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assert(insertedCaseWithNextCallTime.next_call__c <= System.now());
       
      
        //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
  
  static testMethod void getCaseClickedNullNextCallTimePriorityForTest() {
        // Fetch the record type id for West Support
        String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
        
        //Create Cases with null next call time of high priority and next call time with less priority  and insert it
        Case caseWithNextCallTime = new Case(Account=accountAssociatedWithCase,RecordTypeId = westSupportRecordTypeId, next_call__c =(System.now()-100), Status = 'New', Case_Name__c = 'No return LOA',
                                    Priority = '2',Description = 'Test test test', Origin='Phone',Subject='Test');
        Case caseWithNullNextCallTime = new Case(Account=accountAssociatedWithCase,RecordTypeId = westSupportRecordTypeId, next_call__c =null, Status = 'New', Case_Name__c = 'No return LOA',
                                    Priority = '1',Description = 'Test test test2', Origin='Phone',Subject='Test2');
        
       
        insert caseWithNextCallTime;
        insert caseWithNullNextCallTime ;

        // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assert(insertedCaseWithNextCallTime.next_call__c <= System.now());
       
             
        //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
    
    static testMethod void getCaseClickedNullNextCallTimeForTest() {
        // Fetch the record type id for West Support
        String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();
                
        //Create a account for inserting account id in case record
        Account accountAssociatedWithCase=new Account(Name='TestAccount');
        insert accountAssociatedWithCase;
        
        
        //Create Case with next call time and insert it
        Case caseWithNextCallTime = new Case(Account=accountAssociatedWithCase,RecordTypeId = westSupportRecordTypeId, next_call__c =(System.now()-100), Status = 'New', Case_Name__c = 'No return LOA',
                                    Priority = '2',Description = 'Test test test', Origin='Phone',Subject='Test');
        insert caseWithNextCallTime;
        
        // Fetch the inserted case
       Case insertedCaseWithNextCallTime = [SELECT Id, CaseNumber,recordtypeid,ownerid , Priority,Status , Next_Call__c FROM Case WHERE Id = :caseWithNextCallTime.Id]; 
       
       //Check whether insertion done well
       System.assertequals(insertedCaseWithNextCallTime.id,caseWithNextCallTime.id);
       System.assertequals(insertedCaseWithNextCallTime.recordtypeid,Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId());
       System.assertequals(insertedCaseWithNextCallTime.ownerid ,userInfo.getUserId());
       System.assertnotequals(insertedCaseWithNextCallTime.Status ,'Closed');
       System.assert(insertedCaseWithNextCallTime.next_call__c <= System.now());
       
       //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
    
    
    
    static testMethod void getCaseClickedTest() {
        
        //Create an instance of the Console Home Controller
        ConsoleHomeController_AC instanceConsoleHomeController_AC = new ConsoleHomeController_AC();
        instanceConsoleHomeController_AC.getCaseClicked();
        
        
    }
   //Ended by Sreekanth
  */